<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    #app {
      width: 300px;
      height: 300px;
      margin: 50px;
    }
  </style>
</head>
<body>
  <a href="#/boxA">boxA</a>
  <a href="#/boxB">boxB</a>
  <a href="#/boxC">boxC</a>

  <div id="app"></div>

  <script>
    const routes = [
      {
        path: "/boxA",
        element: "<span>我是boxA</span>"
      },
      {
        path: "/boxB",
        element: "<span>我是boxB</span>"
      },
      {
        path: "/boxC",
        element: "<span>我是boxC</span>"
      }
    ]

    const render = () => {
      const targetRoute = routes.find(route => "#" + route.path === location.hash)
      document.getElementById("app").innerHTML = targetRoute.element
    } 
    // 初始化
    render()
    // 监听hashchange事件
    window.addEventListener("hashchange", render)
  </script>
</body>
</html>